package cn.edu.java.stream.functionalinterface;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class ConsumerDemo {
    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");

        Consumer<String> printName1 = new Consumer<String>() {
            @Override
            public void accept(String name) {
                System.out.println(name);
            }
        };
        names.forEach(printName1);

        // 使用Lambda表达式
        Consumer<String> printName2 = (name) -> System.out.println(name);
        names.forEach(printName2);
    }
}

